package learn_concurrent._10;

import java.util.concurrent.atomic.AtomicInteger;

public class CASAccount implements Account {

    private AtomicInteger balance;

    public CASAccount(int balance) {
        this.balance = new AtomicInteger(balance);
    }

    @Override
    public Integer getBalance() {
        return balance.get();
    }

    @Override
    public void withdraw(Integer amount) {
        balance.getAndAdd(-1 * amount);
    }
}
